#!/usr/bin/env python
from os import path
import os
Import('build env module')

build.add_thirdparty(env, 'poco')
if build.is_osx():
    env.Append(LIBS=['xml2'])
    env.Append(CPPPATH=['/usr/include/libxml2'])

if build.is_win32():
    env.Append(CCFLAGS=['/MD', '/DUNICODE', '/D_UNICODE'])
    env.Append(CPPPATH=[
        build.tp('libxml', 'include'),
        build.tp('icu','include')])
    env.Append(LIBPATH = [build.tp('webkit', 'lib')])
    env.Append(LIBS=['libxml2', 'pthreadVC2'])
else:
    env.Append(ENV = {'PATH' : os.environ['PATH']})
    if os.environ.has_key('PKG_CONFIG_PATH'):
        env.AppendENVPath('PKG_CONFIG_PATH', os.environ['PKG_CONFIG_PATH'])
    if not build.is_osx():
        env.ParseConfig('pkg-config --cflags --libs libxml-2.0')

sources = Glob('*.cpp')
if build.is_win32():
    sources += Glob('win/*.cpp')
elif build.is_linux():
    sources += Glob('linux/*.cpp')
elif build.is_osx():
    sources += Glob('mac/*.mm')

build.mark_build_target(env.SharedLibrary(
    path.join(module.dir, 'tiappmodule'), sources))
build.mark_build_target(build.utils.CopyTree(Glob('*.js'), module.dir))
